﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Tools;

namespace Pixysoft.Weblications.Sango.Formular
{
    class MissionFormular
    {
        /** 每日任务最大数目 */
        public const int default_max_dailymission = 6;

        /** 每日活动最高等级 */
        public static int default_max_dailymission_level = 10;

        /** 主线任务根节点 */
        public static long MAINMISSION_ROOT = 0;

        public const int default_dailymission_minlevel = 1;

        /// <summary>
        /// 获取游戏全局任务 类型 现在默认是现金
        /// </summary>
        /// <returns></returns>
        public static long getActivityTypeCode()
        {
            return MissionGlobalCollection.CASH;
        }

        /// <summary>
        /// 每日任务是否可以升级
        /// 1 = upgrade
        /// 0 = draw
        /// -1 = downgrade
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static bool canDailyMissionUpgrade(long missionLevel)
        {
            //当前等级x，随机数y，得到成功率 = 100+k1x, 保持率 = 100 + k2x,其余是失败

            //k1 = 5 – 100/10-1 = 10.555555555555555555555555555556 =- 10.56

            //k2 = -70/9 = -7.78

            double random = SettingHelper.RandomNext(100);

            double successrate = 100 + (-10.56 * missionLevel);

            double drawrate = 100 + (-7.78 * missionLevel);

            if (random < successrate)
                return true;

            return false;
        }

        /// <summary>
        /// 主线任务奖励
        /// </summary>
        /// <param name="mainMission"></param>
        /// <returns></returns>
        public static long getMainmissionCashprize(Pixysoft.Weblications.Sango.Entities.Mis_Mainmission mainMission)
        {
            return mainMission.Prizevalue;
        }

        /// <summary>
        /// 是否每日任务每周刷新
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        public static bool isMissionDailyWeeklyRefresh(Pixysoft.Weblications.Sango.Entities.Usr_Mission activity)
        {
            DateTime currentdate = GlobalTimer.Instance.GetGlobalTime();

            DateTime refreshdate = DateTimeCoder.Instance.GetFirstDayOfCurrentWeek();

            DateTime lastdate = GlobalTimer.Instance.FromTimeSequence((long)activity.Dailylastdate);

            return currentdate >= refreshdate && lastdate < refreshdate;
        }

        /// <summary>
        /// 是否每日任务每天刷新
        /// </summary>
        /// <param name="activity"></param>
        /// <returns></returns>
        public static bool isMissionDailyDailyRefresh(Pixysoft.Weblications.Sango.Entities.Usr_Mission activity)
        {
            DateTime currentdate = GlobalTimer.Instance.GetGlobalTime();

            DateTime refreshdate = DateTimeCoder.Instance.GetHeadOfToday();

            DateTime lastdate = GlobalTimer.Instance.FromTimeSequence((long)activity.Dailylastdate);

            // 如果正好在跨度两边，则跨日

            return currentdate >= refreshdate && lastdate < refreshdate;
        }

        /// <summary>
        /// 每日任务军魂奖励
        /// </summary>
        /// <param name="playerlevel"></param>
        /// <param name="missiontypecode"></param>
        /// <param name="level"></param>
        /// <returns></returns>
        public static long getMissionDailySoulValue(long playerlevel, long missiontypecode, long missionLevel, long buildingLevel)
        {
            //每日任务产出的军魂最大值等效关卡的50%。

            //每日任务一共有10个等级。6个品种。因此产出根据等级进行线性化。

            //10%z*(100+4x)

            return (long)Math.Round(0.1 * missionLevel * (100 + 4 * playerlevel) * (1 + buildingLevel * 0.01));
        }
    }
}
